package org.jxc.service;

import java.util.List;

import org.hibernate.SessionFactory;
import org.jxc.dao.ArriveOrderProductDAO;
import org.jxc.domain.ArriveOrder;
import org.jxc.domain.ArriveOrderProduct;
import org.jxc.domain.PurchaseOrderProduct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.team4.dao.DAOFactory;
import org.team4.exception.CRUDException;
import org.team4.service.IService;

@Service
public class ArriveOrderProductService implements IService {

	private ArriveOrderProductDAO arriveOrderProductDAO;

	@Autowired
	public void setSessionFactory(SessionFactory sessionFactory) {
		arriveOrderProductDAO = (ArriveOrderProductDAO) DAOFactory.getDAO(
				sessionFactory, ArriveOrderProductDAO.class);
	}

	public List<ArriveOrderProduct> findByArriveOrderId(String arriveOrderId)
			throws CRUDException {
		return arriveOrderProductDAO.find(
				"from ArriveOrderProduct where arriveOrderId = ?",
				arriveOrderId);
	}

	/**
	 * 修改采购订单明细
	 * 
	 * @param purchaseOrder
	 * @throws CRUDException
	 */
	public void updateArriveOrderProduct(
			ArriveOrderProduct aop) throws CRUDException {
		ArriveOrderProduct old = arriveOrderProductDAO
				.get(aop.getId());
		old.setAmounts(aop.getAmounts());
		old.setArriveOrder(aop.getArriveOrder());
		old.setInAmounts(aop.getInAmounts());
		old.setPrice(aop.getPrice());
		old.setProduct(aop.getProduct());
		arriveOrderProductDAO.update(old);
	}
	
	public ArriveOrderProduct findById(String id) throws CRUDException {
		return arriveOrderProductDAO.get(id);
	}
}
